package com.ldy.frame;

import javax.swing.*;

/**
 * Created by MacBook Pro on 2017/11/28.
 */
public class TextPanel extends JPanel{
    //创建窗口对象
    JTextArea ta;
    //创建滚动条对象
    JScrollPane jsp;
    public TextPanel(String context)
    {

        //将文本框添加至TextPanel中
        this.add(this.TextSet(context));
    }
    public JScrollPane TextSet(String context) {
        ta = new JTextArea(context, 35, 35);
        //激活自动换行功能
        ta.setLineWrap(true);
        //激活换行不换字功能
        ta.setWrapStyleWord(true);
        //设置为不可编辑
        ta.setEditable(false);
        jsp = new JScrollPane(ta);
        jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        return jsp;
    }
}
